package com.yzs.mvidemo

import android.app.Application
import com.alibaba.android.arouter.launcher.ARouter
import com.blankj.utilcode.util.ProcessUtils
import com.blankj.utilcode.util.Utils
import com.yzs.base.utils.LUtils
import com.yzs.base.utils.SpUtils
import com.yzs.core.momory.AppManager

class App : Application() {

    companion object {
        lateinit var instance: App

        fun get(): App {
            return instance
        }
    }

    override fun onCreate() {
        super.onCreate()
        val isDebug = BuildConfig.DEBUG
        instance = this
        Utils.init(this)
        LUtils.init(if (isDebug) LUtils.DEBUG else LUtils.RELEASE)
        SpUtils.init(this)

        if (ProcessUtils.isMainProcess()) { // 只在主进程初始化
            // 提供给业务层上下文
            AppManager.init(isDebug, this)
            AppManager.baseUrl = "https://www.baidu.com/"

            initARouter(isDebug)
        }
    }

    private fun initARouter(isDebug: Boolean) {
        if (isDebug) {
            ARouter.openDebug()
            ARouter.openLog()
        }
        ARouter.init(this)
    }
}